<template>
    <div class="timeRadio" v-if="song_id">
        <audio :src="song"  autoplay id="audioP"></audio>
        <div class="topP">
            <i class="iconfont icon-xiala-yuan" @click="back"></i>
            <span class="topText">时间电台</span>
            <i class="iconfont icon-more-br"></i>
        </div>
        <div class="playBox">
            <div class="imgBox"><img :src="img" alt=""></div>
            <div class="textBox">
                <p class="songName">{{song_name}}</p>
                <p class="singer">{{artist_name}}</p>
            </div>
            <div class="suspendedBox" @click="play">
                <i v-if="isPlay==false" class="iconfont icon-zanting"></i>
                <i v-else class="iconfont icon-kaishi"></i>
            </div>
        </div>
        <div class="footer">
            <ul class="footUl">
            <li >
                <i class="iconfont icon-xin2 iconAll" @click="xin"></i>
            </li>
            <li>
                <i class="iconfont icon-beishang-yuan iconAll"></i>
            </li>
            <li>
                <i class="iconfont icon-xiazai2 iconAll"></i>
            </li>
            <li>
                <i class="iconfont icon-cibiaoquanyi iconAll"></i>
            </li>
        </ul>
        </div>
        
    </div>
</template>

<script>
import jsonp from "jsonp";

export default {
  name: "timeRadio",
  data() {
    return {
      isPlay: false,
      song: "",
      artist_name: "",
      song_name: "",
      img: "",
      songObj: ""
    };
  },
  computed: {
    //变化属性
    song_id() {
      return this.$route.params.songArr;
    }
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    play() {
      if (this.isPlay) {
        document.querySelector("#audioP").play();
      } else {
        document.querySelector("#audioP").pause();
      }
      this.isPlay = !this.isPlay;
    },
    xin(){
      document.querySelector('.icon-xin2').style.color="#ff7560";
    }

  },
  created() {
    if (!this.songObj) {
      jsonp(
        "http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.playAAC&songid=" +
          this.song_id,
        null,
        (err, res) => {
          if (!err) {
            this.songObj = res;
            this.song = this.songObj.bitrate.show_link;
            this.artist_name = this.songObj.songinfo.artist;
            this.song_name = this.songObj.songinfo.album_title;
            this.img = this.songObj.songinfo.pic_radio;
          } else {
            console.log(err);
          }
        }
      );
    }
  }
};
</script>

<style lang="scss">
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-size: 0;
  z-index: 99;
}
.timeRadio {
  width: 100%;
  height: 100%;
  background: #000;
  color: #fff;
  letter-spacing: 0.09rem;
  overflow: hidden;
  position: relative;
  z-index: 99;
  .topP {
    width: 100%;
    height: 18%;
    padding-top: 0.5rem;
    overflow: hidden;
    text-align: center;
    box-sizing: border-box;
    .icon-xiala-yuan {
      font-size: 1.2rem;
      padding-left: 0.6rem;
      float: left;
      vertical-align: middle;
    }
    .topText {
      display: inline-block;
      font-size: 0.5rem;
      padding-top: 0.2rem;
      vertical-align: middle;
    }
    .icon-more-br {
      font-size: 1.2rem;
      padding-right: 0.5rem;
      float: right;
      vertical-align: middle;
    }
  }
  .playBox {
    width: 70%;
    height: 56%;
    margin: 0 auto;
    position: relative;
    .imgBox {
      width: 100%;
      height: 71%;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .textBox {
      width: 100%;
      height: 29%;
      padding: 0.8rem 0;
      background: #fff;
      text-align: center;
      box-sizing: border-box;
      .songName {
        margin: 0 auto;
        text-align: center;
        font-size: 0.56rem;
        color: #090909;
        overflow: hidden;
        white-space: nowrap; /*强制显示一行*/
        text-overflow: ellipsis; /*溢出文字省略号处理*/
        width: 98%;
      }
      .singer {
        margin: 0 auto;
        text-align: center;
        font-size: 0.43rem;
        color: #676767;
        padding-top: 0.14rem;
        overflow: hidden;
        white-space: nowrap; /*强制显示一行*/
        text-overflow: ellipsis; /*溢出文字省略号处理*/
        width: 98%;
      }
    }
    .suspendedBox {
      display: inline-block;
      width: 2.1rem;
      height: 2.1rem;
      line-height: 2.1rem;
      border-radius: 50%;
      background: #21c5be;
      position: absolute;
      bottom: 2.8rem;
      left: 37%;
      text-align: center;
      .icon-kaishi,
      .icon-zanting {
        display: block;
        font-size: 0.85rem;
        text-align: center;
        position: absolute;
        top: 50%;
        left: 54%;
        transform: translate(-50%, -50%);
      }
    }
  }
  .footer {
    width: 100%;
    height: 26%;
    position: relative;
    .footUl {
      font-size: 0;
      width: 85%;
      margin: 0 auto;
      position: absolute;
      top: 40%;
      left: 50%;
      transform: translate(-50%, 0);
      li {
        width: 25%;
        display: inline-block;
        text-align: center;
        .iconAll {
          font-size: 0.85rem;
        }
      }
    }
  }
}
</style>
